﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FisheryPlatform.Search.Core.Resource;

namespace FisheryPlatform.Search.Core.Analysis
{
    /// <summary>			
    /// FilterFactory
    /// description:	过滤器工厂
    /// create date:	2006-05
    /// author:			gwd
    /// </summary>
    public class FilterFactory
    {
        private System.Collections.Hashtable _filters = null;

        /// <summary>
        /// 构造方法,读取配置文件中的Reserved\Char\Punctuation
        /// </summary>
        /// <param name="reservedFilterPath"></param>
        /// <param name="charFilterPath"></param>
        /// <param name="punctuationFilterPath"></param>
        public FilterFactory(
            CentralPath reservedFilterPath,
            CentralPath charFilterPath,
            CentralPath punctuationFilterPath)
        {
            _filters = new System.Collections.Hashtable();
            LoadCharFilter("Reserved", reservedFilterPath.ToString());
            LoadCharFilter("Char", charFilterPath.ToString());
            LoadCharFilter("Punctuation", punctuationFilterPath.ToString());
            LoadHtmlFilter();
        }

        /// <summary>
        /// get构造方法中实现的filter哈希表
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Filter GetFilter(string name)
        {
            return (Filter)_filters[name.ToLower()];
        }

        /// <summary>
        /// 
        /// </summary>
        private void LoadCharFilter(string name, string fullPath)
        {
            Filter charFilter = new CharFilter(name, fullPath);
            charFilter.LoadFilter();
            _filters.Add(name.ToLower(), charFilter);
        }

        /// <summary>
        /// 
        /// </summary>
        private void LoadHtmlFilter()
        {
            Filter htmlFilter = new HtmlFilter();
            htmlFilter.LoadFilter();
            _filters.Add("Html".ToLower(), htmlFilter);
        }

    }
}
